package com.hjrpc.babyyamall.search.web;

import com.hjrpc.babyyamall.search.service.ProductSearchService;
import com.hjrpc.babyyamall.search.vo.SearchParam;
import com.hjrpc.babyyamall.search.vo.SearchResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;

@Controller
public class SearchController {

    @Autowired
    ProductSearchService productSearchService;

    @RequestMapping({"/","/search.html","list.html"})
    public String listHtml(SearchParam param, Model model, HttpServletRequest request){
        param.setQueryString(request.getQueryString());
        SearchResult result = productSearchService.searchProduct(param);

        model.addAttribute("result",result);
        return "search";
    }
}
